//
//  DetailAlbumsTableViewCell.m
//  AudioBook_A
//
//  Created by Sansan on 15/4/16.
//  Copyright (c) 2015年 Sansan. All rights reserved.
//

#import "DetailAlbumsTableViewCell.h"

@implementation DetailAlbumsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatView];
    }
    
    return self;
}


- (void)creatView
{
    UIView *colorView = [[UIView alloc] initWithFrame:CGRectMake(0, 5, ScreenFram.width, 85)];
    colorView.backgroundColor = [UIColor whiteColor];
    
    self.coverLargeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 10, 60, 60)];
    self.coverLargeImageView.layer.cornerRadius = 30;
    self.coverLargeImageView.layer.masksToBounds = YES;
    [colorView addSubview:self.coverLargeImageView];
    [self.contentView addSubview:colorView];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, ScreenFram.width-120, 40)];
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    self.titleLabel.numberOfLines = 0;
    [self.contentView addSubview:self.titleLabel];
    
    self.nicknameLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 45, ScreenFram.width-120, 20)];
    self.nicknameLabel.font = [UIFont systemFontOfSize:10];
    [self.contentView addSubview:self.nicknameLabel];
    
    self.playtimesLabel = [[UILabel alloc] initWithFrame:CGRectMake(122, 65, 50, 20)];
    self.playtimesLabel.font = [UIFont systemFontOfSize:10];
    [self.contentView addSubview:self.playtimesLabel];
    
    self.durationLabel = [[UILabel alloc] initWithFrame:CGRectMake(202, 65, 50, 20)];
    self.durationLabel.font = [UIFont systemFontOfSize:10];
    [self.contentView addSubview:self.durationLabel];
    
    UIImageView *playImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sound_play.png"]];
    UIView *playView = [[UIView alloc] initWithFrame:CGRectMake(100, 65, 20, 20)];
    [playView addSubview:playImageView];
    [self.contentView addSubview:playView];
    
    UIImageView *clockImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search_hist_tag.png"]];
    UIView *clockView = [[UIView alloc] initWithFrame:CGRectMake(180, 65, 20, 20)];
    [clockView addSubview:clockImageView];
    [self.contentView addSubview:clockView];
    
    UIButton *downLoad = [UIButton buttonWithType:UIButtonTypeCustom];
    downLoad.frame = CGRectMake(ScreenFram.width-40, 60, 28, 24);
    [downLoad setImage:[UIImage imageNamed:@"iconfont-xiazai.png"] forState:UIControlStateNormal];
    [downLoad addTarget:self action:@selector(downloadAction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:downLoad];
}

// 加载图片
- (void)setModel:(TracksModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    self.durationLabel.text = [NSString stringWithFormat:@"%.2f", _model.duration / 60.0];
    self.playtimesLabel.text = [NSString stringWithFormat:@"%ld", _model.playtimes];
    NSString *string = @"by";
    NSString *str = _model.nickname;
    NSString *actor = [NSString stringWithFormat:@"%@ %@", string, str];
    self.nicknameLabel.text = actor;
    self.titleLabel.text = _model.title;
    [self.coverLargeImageView sd_setImageWithURL:[NSURL URLWithString:_model.coverLarge] placeholderImage:[UIImage imageNamed:@"find_hot_albumcover@2x.png"]];
    
    
}

// 下载按钮触发的方法
- (void)downloadAction
{
    NSLog(@"下载触发的方法");
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
